function P = raiseViewPoint(pan,tilt,roll,dist)

% this is a translation from the C++ code:
% rootNode::raiseViewPoint(...);

pan = pan / 180 * pi;
tilt = tilt / 180 * pi;
roll = roll / 180 * pi;
dist = dist *1000;

Rperm = zeros(3,3);
Rperm(1,2)=1; Rperm(2,3)=-1;Rperm(3,1)=-1;

basis = [0 pan 0]';
R_basis= cvRodrigues(basis);
R = R_basis * Rperm;

basis = [tilt 0 0]';
R_basis = cvRodrigues(basis);
R = R_basis * R;

basis = [0 0 roll]';
R_basis = cvRodrigues(basis);
R = R_basis * R;

Tvec = [-dist*cos(tilt)*cos(pan);-dist*cos(tilt)*sin(pan);-dist*sin(tilt)];

f = 600;
K = diag([f f 1]);

R = K * R;
T = R * Tvec;

P = [R,T];

% deformation range is neglected here

end

function R = cvRodrigues(src)

theta = norm(src);
if theta ==0
    R = diag([1 1 1]);
    return;
end

r = src/theta;
rMat = [0 -r(3) r(2); r(3) 0 -r(1); -r(2) r(1) 0];
R = cos(theta)*diag([1 1 1]) + (1-cos(theta))*r*r' + sin(theta)*rMat;

end
